package org.springframework.resource;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * @Author: T-jack
 * @Date: 2023-12-20-10:37
 * @Description:
 */
public class ResourceFormJava {

	/**
	 * java 资源管理对象
	 * @return 获取资源内容
	 */
	public String getResourceFormHttp() {
		String resource = "";
		try {
			// 构建URL 指定资源的协议为http协议
			URL url = new URL("http://www.baidu.com");
			// 打开资源连接
			URLConnection urlConnection = url.openConnection();
			// 获取资源输入流
			InputStream inputStream = urlConnection.getInputStream();

			byte[] bytes = new byte[1024];

			while (inputStream.read(bytes) != -1) {
				resource += new String(bytes);
			}

		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		return resource;

	}
}
